home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-07-18 | 1014 b | 59 lines | [TEXT/PICN] |
- # Concordance program using strings
-
- global uses, lineno, width
-
- procedure main(args)
- local word, line
-
- width := 15 # width of word field
- uses := table("")
- lineno := 0
-
- every tabulate(words()) # tabulate all the citations
-
- output() # print the citations
-
- end
-
- # Add line number to citations for word
- #
- procedure tabulate(word)
-
- if uses[word][-2 -: *lineno] == lineno then return
- else {
- uses[word] ||:= lineno || ", " # new line number
- return
- }
-
- end
-
- # Generate words
- #
- procedure words()
- local s, line
-
- while line := read() do {
- lineno +:= 1
- write(right(lineno,6)," ",line)
- map(line) ? while tab(upto(&letters)) do {
- s := tab(many(&letters))
- if *s < 3 then next # skip short words
- suspend s
- }
- }
-
- end
-
- # Print the results
- #
- procedure output()
- local word
-
- write()
-
- uses := sort(uses,3) # sort citations
- while word := get(uses) do
- write(left(word,width),get(uses)[1:-2])
-
- end
-